﻿@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}




@section Header{

    <script type="text/javascript">

        $(document).ready(function () {
            window.UEDITOR_HOME_URL = "/UploadFile/";
        });


        function submit() {
            //编辑器对象
            var uEditor = UE.getEditor('txt_Introduction');

            //验证输入
            if ($("#txt_ArtWorkName").validatebox('isValid') == false) { return; }

            if (uEditor.hasContents() == false) {
                $.messager.alert('失败', '请输入内容', 'error');
                return;
            }

            //获取附件列表
            var attachmentString = "";
            //---------注意：这个地方有点恶心，冒号分割文件名和保存的的文件名，竖号分割每个附件，在实体类里面进行组装list
            $div = $('#AttarchmentDIV').children('div');
            $div.each(
                function () {
                    attachmentString += $(this).attr('fileName') + ':' + $(this).attr('saveName') + '|';
                }
            );


            //参数对象
            var artWork = {
                ArtistID: $('#cbxArtistName').combobox('getValue'),
                ArtWorkName: $("#txt_ArtWorkName").val(),
                ArtistCategory: $('#cbxArtGroup').combobox('getValue'),
                Spec: $("#txt_Spec").val(),
                SaleTime: $("#txt_SaleTime").datebox('getValue'),
                PrePrice: $("#txt_PrePrice").val(),
                SaleCompany: $("#txt_SaleCompany").val(),
                SaleAuct: $("#txt_SaleAuct").val(),
                AuctState: $('#cboAutState').combobox('getValue'),
                TransactionPrice: $("#txt_TransactionPrice").val(),
                Introduction: uEditor.getContent(),
                AttarchmentString: attachmentString
            };

            $.post("/ArtWork/AddArtWork/", artWork,
                    function (data, textStatus) {
                        if (data == 'success') {
                            $("#txt_Title").val(""); //清空
                            uEditor.setContent(""); //清空
                            $('#AttarchmentDIV').empty();

                            $.messager.alert('成功', '添加成功', 'info');
                        }
                        else { $.messager.alert('失败', data, 'error'); }
                    }
            );
        }

        function removeAttarchment(divID) {
            $('#' + divID).remove();
        }

        //附件上传成功
        function onUploadSuccess(file, data, response) {
            eval("data=" + data);
            var fileId = data.FileID;
            $('#AttarchmentDIV').append('<div id="' + fileId + '" fileName = "' + file.name + '" saveName = "' + data.SaveName + '">' + file.name + '<a href = "#" onclick = "removeAttarchment(\'' + fileId + '\')">删除</a></div>');
        }
    </script>
}

<body>

    <div>
        作品名称:
        @Html.TextBox("txt_ArtWorkName", "", new { size = 50, @class = "easyui-validatebox", required = "true" })
        <br />
        艺术家:
    <select id="cbxArtistName" class="easyui-combobox" name="state" style="width: 200px;">
        @{ 
            IList<ArtistInfo> artist = ViewBag.Artist as List<ArtistInfo>;
            foreach (ArtistInfo item in artist)
            { 
            <option value="@item.ArtistID">@item.ArtistName</option>  
            }
        }
    </select>
        <br />
        作品分类:
        <select id="cbxArtGroup" class="easyui-combobox" name="state" style="width: 200px;">
            @{
                foreach (string item in ViewBag.ArtGroup)
                {
                <option value="@item">@item</option>
                }
            }
        </select>
        <br />
        作品规格:
        @Html.TextBox("txt_Spec", "", new { size = 50, @class = "easyui-validatebox", required = "true" })
        <br />
        作品价格:
        @Html.TextBox("txt_PrePrice", "", new { size = 50, @class = "easyui-numberbox", required = "false" })
        <br />
        拍卖时间: 
        @Html.TextBox("txt_SaleTime", "", new { size = 50, @class = "easyui-datebox", required = "false" })
        <br />
        拍卖公司:
        @Html.TextBox("txt_SaleCompany", "", new { size = 50, @class = "easyui-validatebox", required = "false" })
        <br />
        拍卖会:
        @Html.TextBox("txt_SaleAuct", "", new { size = 50, @class = "easyui-validatebox", required = "false" })
        <br />
        拍卖状态:
        <select id="cboAutState" class="easyui-combobox" name="dept" style="width: 200px;">
            <option value="aa">预展</option>
            <option>未拍卖</option>
            <option>已拍卖</option>
        </select>
        <br />
        成交价:
        @Html.TextBox("txt_TransactionPrice", "", new { size = 50, @class = "easyui-numberbox", required = "false" })
        <br />
        @* 简介 *@
        @Html.UEditor("txt_Introduction")
        <br />
        @Html.Uploader("file_uploader", "onUploadSuccess")
        <div id="AttarchmentDIV"></div>

        <p>
            <input type="button" value="添加" onclick="submit()" />
        </p>
    </div>
</body>
